<?php
namespace  App\server\sendsms;

/**
 * Class HxSms
 * @package App\server\sendsms
 * 环信
 */
class HxSms implements Sms
{
    public function sendSms($phone)
    {
        // TODO: Implement sendSms() method.
        $accountSid = '2c948876870df82e01871192fce900aa';
        //主帐号Token
        $accountToken = 'b04519efa3f24494a2a72daff956dbf5';
        //应用Id
        $appId = '2c94811c87983b6b01879cada8b8005e';
        //请求地址，格式如下，不需要写https://
        $serverIP = 'app.cloopen.com';
        //请求端口
        $serverPort = '8883';
        //REST版本号
        $softVersion = '2013-12-26';
        // 初始化REST SDK
        $rest = new REST($serverIP, $serverPort, $softVersion);
        $rest->setAccount($accountSid, $accountToken);
        $rest->setAppId($appId);

        // 发送模板短信
        $code=mt_rand(1111,4444);
        echo "Sending TemplateSMS to $phone <br/>";
        $result = $rest->sendTemplateSMS($phone, $code,1);
        if ($result == NULL) {
            echo "result error!";

        }
        if ($result->statusCode != 0) {
            echo "error code :" . $result->statusCode . "<br>";
            echo "error msg :" . $result->statusMsg . "<br>";
            //TODO 添加错误处理逻辑
        } else {
            echo "Sendind TemplateSMS success!<br/>";
            // 获取返回信息
            $smsmessage = $result->TemplateSMS;
            echo "dateCreated:" . $smsmessage->dateCreated . "<br/>";
            echo "smsMessageSid:" . $smsmessage->smsMessageSid . "<br/>";
            //TODO 添加成功处理逻辑
        }
    }
}
